import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'details.dart';
import 'classificationList.dart';
// import 'photos.dart';
import 'package:share_plus/share_plus.dart';
import 'dart:io';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:path_provider/path_provider.dart';
// import 'package:whatsapp_share/whatsapp_share.dart';
import 'package:image_picker/image_picker.dart';
import 'tab.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'common/loading_spinner.dart'; // 导入公共组件
import 'common/api_service.dart'; // 导入 ApiService 类
import 'package:cached_network_image/cached_network_image.dart'; //网络图片缓存到本地
import 'dart:async';
import 'card/category_card.dart';
import 'message/category_message.dart';
import 'diy/diy.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'ads/ads_unit_id.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'classificationList.dart';
import 'app_color.dart';

class HomePage extends StatefulWidget {
  const HomePage({
    super.key,
  });

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool isMember = false;

  List<String> favoriteList = [];
  List<String> classificationsList = [];
  List<String> DaysClassificationsList = [];
  List<Map<String, dynamic>> remmodedItems = [];
  bool isLoading = false;
  bool isTryAgain = false;
  Map<String, dynamic> newCategory = {};

  List categoryList = []; // 类别数据
  Map<String, dynamic> trendData = {};

  final controller = ScrollController();

  static const _insets = 12.0;
  BannerAd? _inlineAdaptiveAd;
  bool _isLoaded = false;
  BannerAd? _inlineAdaptiveAd2;
  bool _isLoaded2 = false;
  AdSize? _adSize;
  // late Orientation _currentOrientation;
  double get _adWidth => MediaQuery.of(context).size.width - (2 * _insets);

  // @override
  // void didChangeDependencies() {
  //   super.didChangeDependencies();
  //   _currentOrientation = MediaQuery.of(context).orientation;
  //   _loadAd();
  // }

  Future<int> _getAdStatus() async {
    final prefs = await SharedPreferences.getInstance();
    int status = prefs.getInt('inlineAdStatus') ?? 1;
    return status;
  }

  void _loadInlineAd() async {
    int adStatus = await _getAdStatus();
    if (adStatus != 1) {
      return;
    }

    await _inlineAdaptiveAd?.dispose();
    setState(() {
      _inlineAdaptiveAd = null;
      _isLoaded = false;
    });

    // Get an inline adaptive size for the current orientation.
    AdSize size = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(
        _adWidth.truncate());

    _inlineAdaptiveAd = BannerAd(
      // TODO: replace this test ad unit with your own ad unit.
      adUnitId: AdsUnitId.inlineAdaptive,
      size: size,
      request: AdRequest(),
      listener: BannerAdListener(
        onAdLoaded: (Ad ad) async {
          // print('Inline adaptive banner loaded: ${ad.responseInfo}');

          // After the ad is loaded, get the platform ad size and use it to
          // update the height of the container. This is necessary because the
          // height can change after the ad is loaded.
          BannerAd bannerAd = (ad as BannerAd);
          final AdSize? size = await bannerAd.getPlatformAdSize();
          if (size == null) {
            print('Error: getPlatformAdSize() returned null for $bannerAd');
            return;
          }

          setState(() {
            _inlineAdaptiveAd = bannerAd;
            _isLoaded = true;
            _adSize = size;
          });
        },
        onAdFailedToLoad: (Ad ad, LoadAdError error) {
          print('Inline adaptive banner failedToLoad: $error');
          ad.dispose();
        },
      ),
    );
    await _inlineAdaptiveAd!.load();
  }

  void _loadInlineAd2() async {
    int adStatus = await _getAdStatus();
    if (adStatus != 1) {
      return;
    }

    await _inlineAdaptiveAd2?.dispose();
    setState(() {
      _inlineAdaptiveAd2 = null;
      _isLoaded2 = false;
    });

    // Get an inline adaptive size for the current orientation.
    AdSize size = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(
        _adWidth.truncate());

    _inlineAdaptiveAd2 = BannerAd(
      // TODO: replace this test ad unit with your own ad unit.
      adUnitId: AdsUnitId.inlineAdaptive,
      size: size,
      request: AdRequest(),
      listener: BannerAdListener(
        onAdLoaded: (Ad ad) async {
          // print('Inline adaptive banner loaded: ${ad.responseInfo}');

          // After the ad is loaded, get the platform ad size and use it to
          // update the height of the container. This is necessary because the
          // height can change after the ad is loaded.
          BannerAd bannerAd = (ad as BannerAd);
          final AdSize? size = await bannerAd.getPlatformAdSize();
          if (size == null) {
            print('Error: getPlatformAdSize() returned null for $bannerAd');
            return;
          }

          setState(() {
            _inlineAdaptiveAd2 = bannerAd;
            _isLoaded2 = true;
            _adSize = size;
          });
        },
        onAdFailedToLoad: (Ad ad, LoadAdError error) {
          print('Inline adaptive banner failedToLoad: $error');
          ad.dispose();
        },
      ),
    );
    await _inlineAdaptiveAd2!.load();
  }

  Widget _getAdWidget() {
    return OrientationBuilder(
      builder: (context, orientation) {
        if (
            _inlineAdaptiveAd != null &&
            _isLoaded &&
            _adSize != null) {
          return Align(
              child: Container(
                margin: const EdgeInsets.only(top: 12),
            width: _adWidth,
            height: _adSize!.height.toDouble(),
            child: AdWidget(
              ad: _inlineAdaptiveAd!,
            ),
          ));
        }
        // Reload the ad if the orientation changes.
        // if (_currentOrientation != orientation) {
        //   _currentOrientation = orientation;
        //   _loadAd();
        // }
        return Container();
      },
    );
  }

  Widget _getAdWidget2() {
    return OrientationBuilder(
      builder: (context, orientation) {
        if (
            _inlineAdaptiveAd2 != null &&
            _isLoaded2 &&
            _adSize != null) {
          return Align(
              child: Container(
                // margin: const EdgeInsets.only(top: 12),
            width: _adWidth,
            height: _adSize!.height.toDouble(),
            child: AdWidget(
              ad: _inlineAdaptiveAd2!,
            ),
          ));
        }
        // Reload the ad if the orientation changes.
        // if (_currentOrientation != orientation) {
        //   _currentOrientation = orientation;
        //   _loadAd();
        // }
        return Container();
      },
    );
  }

  // 调用公共方法
  void fetchData() async {
    print('发起请求');
    setState(() {
      isLoading = true;
    });
    try {
      String url = 'https://apken.oss-us-west-1.aliyuncs.com/goodmorning-es/json/category.json'; // 替换为你的 URL
      List<dynamic> jsonData = await ApiService.fetchJsonData(url);

      setState(() {
        isTryAgain = false;
        isLoading = false;
        categoryList = jsonData[0]['list'];
        trendData = jsonData[0]['trend'];
        newCategory = jsonData[0]['new_category'];
        
      });
      getFavoriteList();
      // _loadAd();
    } catch (e) {
      setState(() {
        isTryAgain = true;
        isLoading = false;
      });
    }
  }

  _saveIntList(favoriteList) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setStringList('favoriteList', favoriteList);
  }

  Future<List<String>> _getIntList() async {
    final prefs = await SharedPreferences.getInstance();
    List<String> favoriteList = prefs.getStringList('favoriteList') ?? [];
    return favoriteList;
  }

  Future<void> getFavoriteList() async {
    // setState(() {
    //   trendData = trendData;
    // });
    List<String> favoriteList = await _getIntList();
    print('返回的收藏列表'+favoriteList.toString());
    List<int> likeList = [];
    for(int item in trendData['id']){
      if(favoriteList.contains(item.toString())){
        likeList.add(1);
      }else{  
        likeList.add(0);
      }
    }

    setState(() {
      favoriteList = favoriteList;
      trendData['likeList'] = likeList;
      // trendData = trendData;
    });

    print(trendData);
  }


  @override
  void dispose() {
    _inlineAdaptiveAd!.dispose();
    _inlineAdaptiveAd2!.dispose();
    super.dispose();
  }


  @override
  void initState() {
    super.initState();
    _loadInlineAd();
    _loadInlineAd2();
    fetchData();
    
  }

  @override
  Widget build(BuildContext context) {
    var sizewidth = MediaQuery.of(context).size.width;
    var topHeight = MediaQuery.of(context).padding.top;
    
    return isLoading ? const Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          LoadingSpinner()
        ],
      )  : Container(
      padding:  EdgeInsets.only(top: topHeight, left: 10, right: 10),
      child: SingleChildScrollView(
            controller: controller, 
            child:  Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          const SizedBox(height: 16),
          if(newCategory.isNotEmpty)
            InkWell(
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => ClassificationListPage(
                      classificationItem: newCategory,
                    ),
                  ),
                );
              },
              child: Container(
                height: 42,
                margin: const EdgeInsets.only(bottom: 12),
                width: sizewidth,
                decoration: BoxDecoration(
                  border: Border.all(width: .5, color: Colors.black26),
                  borderRadius: BorderRadius.circular(8),
                  // color: AppColors.primary,
                ),
                child: Container(
                  padding: const EdgeInsets.only(left: 12, right: 12),
                  child: Row(
                    children: [
                      Image.asset('images/${newCategory['type'] == 'new' ? 'new' : 'hot'}.png', width: 24, height: 24,),
                      const SizedBox(width: 12,),
                      Text(newCategory['category'], style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, height: 1.2,), textAlign: TextAlign.center,),
                    ],
                    
                    ) 
                ) ,
              ),
            ),
          Row(
            children: [
              Expanded(
                child: InkWell(
                  onTap: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => const CategoryCardPage(),
                      ),
                    );
                  },
                  child: Container(
                    height: 100,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(8),
                      image: const DecorationImage(
                        image: AssetImage('images/images.webp'),
                        fit: BoxFit.cover
                      )
                    ),
                    child: Container(
                      padding: const EdgeInsets.only(left: 12, right: 12),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(4),
                        gradient: const LinearGradient(
                          begin: Alignment.topLeft,
                          end: Alignment.bottomLeft,
                          colors: [
                            Color.fromRGBO(0, 0, 0, .1),
                            Color.fromRGBO(0, 0, 0, 0.6)
                          ],
                        ),
                      ),
                      
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            const Text('Tarjeta de los mejores deseos.', style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold, height: 1.2,), textAlign: TextAlign.center,),
                            const SizedBox(height: 8,),
                            Container(
                              padding: const EdgeInsets.all(6),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(30),
                                color: const Color.fromARGB(255, 215, 31, 39)
                              ),
                              child: const Icon(CupertinoIcons.arrow_right, color: Colors.white, size: 16,),
                            )
                            
                          ],
                        ) 
                    ) ,
                  )
                )
              ),
              const SizedBox(width: 10),
              Expanded(
                child: InkWell(
                  onTap: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => const CategoryMessagePage(),
                      ),
                    );
                  },
                  child: Container(
                    height: 100,
                    decoration: BoxDecoration(
                      // border: Border.all(width: 1),
                      borderRadius: BorderRadius.circular(4),
                      image: const DecorationImage(
                        image: AssetImage('images/message.jpg'),
                        fit: BoxFit.cover
                      )
                    ),
                    child: Container(
                      padding: const EdgeInsets.only(left: 12, right: 12),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(8),
                        gradient: const LinearGradient(
                          begin: Alignment.topLeft,
                          end: Alignment.bottomLeft,
                          colors: [
                            Color.fromRGBO(0, 0, 0, .3),
                            Color.fromRGBO(0, 0, 0, 0.6)
                          ],
                        ),
                      ),
                      
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            const Text('Mensajes de los mejores deseos', style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold, height: 1.2,), textAlign: TextAlign.center,),
                            const SizedBox(height: 8,),
                            Container(
                              padding: const EdgeInsets.all(6),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(30),
                                color: const Color.fromARGB(255, 215, 31, 39)
                              ),
                              child: const Icon(CupertinoIcons.arrow_right, color: Colors.white, size: 16,),
                            )
                            
                          ],
                        ) 
                    ) ,
                  )
                )
              ),
            ],
          ),
          const SizedBox(height: 12,),
          
          InkWell(
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => const DiyPage(),
                ),
              );
            },
            child: Container(
              height: 90,
              width: sizewidth,
              decoration: BoxDecoration(
                // border: Border.all(width: 1),
                borderRadius: BorderRadius.circular(8),
                image: const DecorationImage(
                  image: AssetImage('images/diy.jpg'),
                  fit: BoxFit.cover
                )
              ),
              child: Container(
                padding: const EdgeInsets.only(left: 12, right: 12),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8),
                  gradient: const LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomLeft,
                    colors: [
                      Color.fromRGBO(0, 0, 0, .1),
                      Color.fromRGBO(0, 0, 0, 0.6)
                    ],
                  ),
                ),
                
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      const Text('Hacer una tarjeta para un amigo.', style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold, height: 1.2,), textAlign: TextAlign.center,),
                      const SizedBox(height: 8,),
                      Container(
                        padding: const EdgeInsets.all(6),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(30),
                          color: const Color.fromARGB(255, 215, 31, 39)
                        ),
                        child: const Icon(CupertinoIcons.add, color: Colors.white, size: 16,),
                      )
                      
                    ],
                  ) 
              ) ,
            ),
          ),
          
          _getAdWidget(),
          
          const SizedBox(height: 12,),
          if(trendData.isNotEmpty)
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const SizedBox(height: 4),
              const Text(
                'Tarjeta de Felicitación Popular',
                style: TextStyle(fontSize: 18, fontFamily: 'OpenSans', fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 12),
              Align(
                alignment: Alignment.topLeft,
                child: Wrap(
                  spacing: 10.0,
                  runSpacing: 10.0,
                  children: [
                    
                    for (int index = 0; index < trendData['id'].length; index++)...[
                       // Text(trendData['likeList'][index].toString())
                      Recommend(
                        imgId: trendData['id'][index],
                        sizewidth: sizewidth,
                        gif: trendData['gif'][index], // 使用当前索引
                        like: trendData['likeList'][index],
                      ),
                      if (index == 3) 
                        _getAdWidget2(), // 替换为你的广告组件
                    ]
                     
                  ],
                ),
              ),
              const SizedBox(height: 10,),
              InkWell(
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const CategoryCardPage(),
                    ),
                  );
                },
                child: Container(
                  height: 64,
                  decoration: BoxDecoration(
                    color: const Color.fromARGB(255, 255, 251, 0),
                    border: Border.all(width: 1),
                    borderRadius: BorderRadius.circular(8)
                  ),
                  child: const Center(
                    child: Text('Navegar por categoría', style: TextStyle(fontSize: 20, fontFamily: 'OpenSans'),),
                  ) 
                )
              ),
              const SizedBox(height: 10,),
            ],
          ),
          
          // const Row(
          //   mainAxisAlignment: MainAxisAlignment.center,
          //   children: [
          //     Text(
          //       '>>> no more <<<',
          //       style: TextStyle(color: Colors.black38, fontSize: 12),
          //     )
          //   ],
          // )
        ],
      ),
    ));
  
  }
}

class classification extends StatelessWidget {
  // final String classificationItem;
  Map<String, dynamic> classificationItem;
  final VoidCallback backRefresh;
  classification({
    super.key,
    required this.classificationItem,
    required this.backRefresh,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(top: 8, bottom: 8),
      child: GestureDetector(
        onTap: () async {
          final result = await Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => ClassificationListPage(
                classificationItem: classificationItem,
              ),
            ),
          );
          if (result != null && result is String) {
            print('fanhui ');
            backRefresh();
          }
        },
        child: Stack(
          children: [
            Container(
              width: 270,
              height: 120,
              margin: const EdgeInsets.only(right: 10),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(8),
                child:CachedNetworkImage(
                  imageUrl: 'https://apken.oss-us-west-1.aliyuncs.com/goodmorning-es/category/${classificationItem['slug']}.webp',
                  placeholder: (context, url) => const LoadingSpinner(), // 占位图
                  errorWidget: (context, url, error) => const Icon(Icons.error), // 错误图标
                  fit: BoxFit.cover,
                )
              ),
            ),
            Positioned(
              bottom: 0,
              child: Container(
                padding: const EdgeInsets.only(left: 10, right: 10),
                decoration: const BoxDecoration(
                  borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(8),
                    bottomRight: Radius.circular(8),
                  ),
                  color: Color.fromRGBO(0, 0, 0, 0.4),
                ),
                width: 270,
                height: 40,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      classificationItem['category'],
                      style: const TextStyle(
                          color: Colors.white, fontFamily: 'OpenSans', fontWeight: FontWeight.bold),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

class Recommend extends StatefulWidget {
  final int imgId;
  final double sizewidth;
  final int gif;
  final int like;

  const Recommend({
    super.key,
    required this.imgId,
    required this.sizewidth,
    required this.gif,
    required this.like
  });
  @override
  State<Recommend> createState() => RecommendAssembly();
}

class RecommendAssembly extends State<Recommend> {
  // List<String> favoriteList = [];
  // Map recommendImgItem = {};
  final _HomePageState _aInstance = _HomePageState();
  List<String> favoriteList = [];
  int imgId = 0;
  int gif = 0;
  int like = 0;

  @override
  void initState() {
    super.initState();

    setState(() {
      imgId = widget.imgId;
      gif =  widget.gif;
      like = widget.like;
    });

    // print('---更新子元素');
    // print(widget.like);

  }
  // Future<void> shareAssetImage(String assetName) async {
  //   try {
  //     final bytes = await rootBundle.load(assetName);
  //     final tempDir = await getTemporaryDirectory();
  //     final tempFile = File('${tempDir.path}/shared_image.jpg');
  //     await tempFile.writeAsBytes(bytes.buffer.asUint8List());
  //     await Share.shareXFiles(
  //       [XFile(tempFile.path)],
  //       text: 'Please review the shared images',
  //       sharePositionOrigin: const Rect.fromLTWH(0, 0, 100, 100),
  //       subject: 'Shared Image',
  //     );
  //   } catch (e) {
  //     print('Error sharing asset image: $e');
  //   }
  // }

  // Future<void> shareFileToWhatsApp(String assetName, String phone) async {
  //   try {
  //     final bytes = await rootBundle.load(assetName);
  //     final tempDir = await getTemporaryDirectory();
  //     final tempFile = File('${tempDir.path}/shared_image.jpg');
  //     await tempFile.writeAsBytes(bytes.buffer.asUint8List());
  //     await WhatsappShare.shareFile(
  //       phone: phone,
  //       filePath: [tempFile.path],
  //     );
  //   } catch (e) {
  //     print('Error sharing asset image: $e');
  //   }
  // }
  static FirebaseAnalytics analytics = FirebaseAnalytics.instance;
  void _logFavoriteEvent(String itemId) async {
    await FirebaseAnalytics.instance.logEvent(
      name: "favorite_image",
      parameters: {
          // "content_type": "image",
          "image_id": itemId,
      },
    );
  }
  

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => DetailPage(imgId: imgId, gif: gif),
          ),
        );
      },
      child: Stack(
        children: [
          Container(
            width: (widget.sizewidth - 30) / 2,
            height: (widget.sizewidth - 30) / 2,
            child: ClipRRect(
                borderRadius: BorderRadius.circular(4),
                child:CachedNetworkImage(
                  imageUrl: 'https://apken.oss-us-west-1.aliyuncs.com/goodmorning-es/images/$imgId.${gif==0?'webp?x-oss-process=image/resize,p_40':'gif'}',
                  placeholder: (context, url) => const LoadingSpinner(), // 占位图
                  errorWidget: (context, url, error) => const Icon(Icons.error), // 错误图标
                  fit: BoxFit.cover,
                )
              ),
          ),
          if(gif == 1)
          Positioned(
            left: 5,
            top: 5,
            child: Container(
              width: 36,
              height: 28,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(18),
                color: const Color.fromRGBO(255, 255, 255, .7),
              ),
              child: const Center(
                child: Text('GIF',style: TextStyle( fontSize: 14),),
              ),
            )
          ),
          Positioned(
            bottom: 0,
            left: 0,
            right: 0,
            child: Container(
              padding: const EdgeInsets.only(left: 10, right: 10, bottom: 10),
              decoration: const BoxDecoration(
                borderRadius: BorderRadius.only(
                  bottomLeft: Radius.circular(8),
                  bottomRight: Radius.circular(8),
                ),
                // gradient: LinearGradient(
                //   begin: Alignment.topLeft,
                //   end: Alignment.bottomLeft,
                //   colors: [
                //     Color.fromRGBO(0, 0, 0, 0),
                //     Color.fromRGBO(0, 0, 0, 0.5)
                //   ],
                // ),
              ),
              height: 80,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  GestureDetector(
                    onTap: () async {
                      
                      List<String> favoriteList =
                            await _aInstance._getIntList();
                        setState(() {
                          String itemId = imgId.toString();
                          if (favoriteList.contains(itemId)) {
                            favoriteList.remove(itemId);
                            like = 0;
                          } else {
                            favoriteList.add(itemId);
                            like = 1;
                            _logFavoriteEvent(itemId);
                          }
                        });
                        print(favoriteList);
                        await _aInstance._saveIntList(favoriteList);
                        
                    },
                    child: Container(
                      padding: const EdgeInsets.all(5),
                      decoration: const BoxDecoration(
                        color: Color.fromRGBO(0, 0, 0, .75),
                        borderRadius: BorderRadius.all(Radius.circular(4)),
                      ),
                      child: Icon(
                        Icons.favorite,
                        size: 28,
                        color: like == 1
                            ? const Color.fromARGB(255, 252, 229, 13)
                            : Colors.white,
                      ),
                    ) ,
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
